/* Copyright (C) 2010 Fredrique Samuels, fredriquesamuels@gmail.com */

/*
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef TRI_CONTEXT_H_
#define TRI_CONTEXT_H_

#include "events.h"

namespace tri
{

class TContext
{
public:
	TContext();
	virtual ~TContext();
	
	/**
	 * Displays the current graphics to the screen.
	 */
	virtual void display()=0;
	
	/**
	 * Called when Display window is resized
	 */
	virtual void resize(int width,int height)=0;
	
	/**
	 * Called when apllication states.
	 * Sets up all the needed configs
	 */
	virtual void init()=0;
	
	/**
	 * Called on key events
	 */
	virtual void keyUp(int key) = 0;
	
	/**
	 * Called on key events
	 */
	virtual void keyDown(int key) = 0;
	
	
	//mouse interaction
	virtual void mouseDrag(int x,int y,int xrel,int yrel,int button)= 0;
	virtual void mouseMove(int x,int y,int xrel,int yrel)= 0;
	virtual void mouseUp(int x,int y,int button)= 0;
	virtual void mouseDown(int x,int y,int button)= 0;
	
	
	//stored events
	void setLastMousePosition(int x,int y);
	void getLastMousePosition(int& x,int& y);
	
	void setLastButtonPressed(int b);
	int getLastButtonPressed();
	
private:
	int _last_mouse_position[2];
	int _last_button_pressed;
};

class TWindow{
public:
	TWindow();
	virtual ~TWindow();
	
	/**
	 * Run the application window
	 */
	void run(int width,int height,std::string caption,bool fullscreen);
	
	/**
	 * set the graphics context 
	 * 
	 * @param c : Graphics context
	 */
	void setContext(TContext* c);
	
protected:
	virtual void start(int width,int height,std::string caption,bool fullscreen)=0;
	TContext *_context;
};

}

#endif /*CONTEXT_H_*/
